package com.zzptc.myk.a1030;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    private GridView mGridView;
    int[] tupian={R.mipmap.vx,R.mipmap.qq,R.mipmap.rl,R.mipmap.xj,R.mipmap.xc,R.mipmap.dt};
    String [] titles={"微信","QQ","日历","相机","视频","地图"};
    List<Map<String ,Object>> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mGridView = findViewById(R.id.grid_view);
        list =new ArrayList<>();
        getData();
        String[] from={"icon","biaoti"};
        int[] to={R.id.iv_pic,R.id.tv_title};
        SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, list, R.layout.item, from, to);
        mGridView.setAdapter(simpleAdapter);
    }

    private void getData() {
        for (int i=0;i<titles.length;i++) {
            Map<String,Object> map =new HashMap<>();
            map.put("biaoti", titles[i]);
            map.put("icon", tupian[i]);
            list.add(map);
        }
    }
}
